import axios from "axios"
import { getInfo, setInfo, removeInfo } from '@/utils/storage'

// const sonIndex = [
//     {
//         path: "/",
//         name: "page",
//         label: "首页",
//         icon: "s-tools",
//         url: "gfg"
//     }
// ]

export default {
    namespaced: true,
    state() {
        return {
            title: '这是一个首页的 共享数据',
            cartList: [],
            // tabsList: sonIndex,
            tabsList: getInfo(),
            isCollapse: false,
        }
    },
    mutations: {
        nvaLapse(state) {
            state.isCollapse = !state.isCollapse
        },
        // nvaList(state, res) {
        nvaList(state, res) {
            // localStorage.setItem('DataList', JSON.stringify(res.data))

            // const row = JSON.parse(localStorage.getItem('DataList'))
            // console.log(row, '=====row');

            state.cartList = res.data
            // state.cartList = row
        },
        // 更新面包屑
        selectMenu(state, val) {

            const objList = state.tabsList
            console.log(state.tabsList, '0-0-');

            setInfo(objList)
            // 判断添加数据是否为首页
            if (val.name !== 'page') {
                const index = objList.findIndex(item => item.name === val.name)
                // 如果不存在
                if (index === -1) {
                    objList.push(val)
                }
            }
            // const objList = state.tabsList
            // console.log(state.tabsList, '0-0-');

            // setInfo(val)
            // // 判断添加数据是否为首页
            // if (val.name !== 'page') {
            //     const index = state.tabsList.findIndex(item => item.name === val.name)
            //     // 如果不存在
            //     if (index === -1) {
            //         state.tabsList.push(val)
            //     }
            // }
        },
        // 点击删除指定tag数据
        closeTag(state, val) {
            const index = state.tabsList.findIndex(item => item.name === val.name)
            state.tabsList.splice(index, 1)
            removeInfo()
        },
        // postList(state, val) {
        //     console.log(state, val, '00=');
        // }
    },
    actions: {
        async getNavList(context) {
            const res = await axios.get('http://localhost:3000/getList')
            // localStorage.setItem('DataList', JSON.stringify(res.data))
            // context.commit('nvaList')
            context.commit('nvaList', res)
        },
        // 添加导航组件
        async submitList(context, val) {
            console.log(val, 'h');
            const yy = await axios({
                method: 'post',
                url: "http://localhost:3000/getList",
                data: {
                    val
                }
            })

            console.log(yy, 'yy');
        }
    },
    getters: {

    }
}